 //面试题 04.06.后继者
 //https://leetcode.cn/problems/successor-lcci/
class Solution {
public:
    TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {
        if(!root) return root;

        //p在当前树的左侧 去左侧继续找最接近的 如果root就是最接近的就返回root
        if(root->val > p->val) return (p=inorderSuccessor(root->left,p))?p:root;
        //否则去右树找
        return inorderSuccessor(root->right,p);
    }
};